﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;
using PlugNT.Cms.Web.Zfb.db.Gateway;

namespace PlugNT.Cms.Web.Zfb.db
{
    public partial class Buy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnAlipay_Click(object sender, EventArgs e)
        {
            #region 支付宝业务参数
            string gateway = "https://www.alipay.com/cooperate/gateway.do?";	//支付接口
            string service = "create_partner_trade_by_buyer";                           //服务名称

            string seller_email = PlugNT.Custom.WebConfig.AlipaySelleremail;				        //支付宝帐号
            string sign_type = "MD5";                                           //加密类型,签名方式“不用改”
            string key = PlugNT.Custom.WebConfig.AlipayKey;                    //安全校验码
            string partner = PlugNT.Custom.WebConfig.AlipayPartner;		                        //商户ID，合作ID
            string _input_charset = "gb2312";                                   //编码类型

            string show_url = "www.alipay.com";                                 //展示地址，支付页时商品名称旁的详情的链接地址

            string out_trade_no = TxtOrderno.Text.Trim();                       //客户网站订单号，（现取系统时间，可改成网站自己的变量）
            string subject = TxtSubject.Text.Trim();                            //商品名称
            string body = TxtBody.Text.Trim();                                  //商品描述
            string price = TxtPrice.Text.Trim();                                //商品价格
            string quantity = TxtQua.Text.Trim();                               //商品数量

            string logistics_type = "POST";                                     //物流配送方式：POST(平邮)、EMS(EMS)、EXPRESS(其他快递)
            string logistics_fee = TxtPost.Text.Trim();                         //物流配送费用
            string logistics_payment = "BUYER_PAY";                             //物流配送费用付款方式：SELLER_PAY(卖家支付)、BUYER_PAY(买家支付)、BUYER_PAY_AFTER_RECEIVE(货到付款)

            //服务器通知url（Alipay_Notify.asp文件所在路经）
            string notify_url = "http://www.plugnet.cn/Zfb/db/Alipay_Notify.aspx";
            //服务器返回url（return_Alipay_Notify.asp文件所在路经）
            string return_url = "http://www.plugnet.cn/Zfb/db/Alipay_Return.aspx";
            //相关参数名称具体含义，可以在支付宝接口服务文档中查询到，
            //以上两个文件，通知正常都可以在notify data目录找到通知过来的日志

            string aliay_url = AliPay.CreatUrl(
                gateway,
                service,
                partner,
                sign_type,
                out_trade_no,
                subject,
                body,
                price,
                show_url,
                seller_email,
                key,
                return_url,
                _input_charset,
                notify_url,
                logistics_type,
                logistics_fee,
                logistics_payment,
                quantity
                );

            //以下是POST方式传递参数
            Response.Write("<form name='alipaysubmit' method='post' action='https://www.alipay.com/cooperate/gateway.do?'>");
            Response.Write("<input type='hidden' name='service' value=" + service + ">");
            Response.Write("<input type='hidden' name='partner' value=" + partner + ">");
            Response.Write("<input type='hidden' name='sign_type' value=" + sign_type + ">");
            Response.Write("<input type='hidden' name='out_trade_no' value=" + out_trade_no + ">");
            Response.Write("<input type='hidden' name='subject' value=" + subject + ">");
            Response.Write("<input type='hidden' name='body' value=" + body + ">");
            Response.Write("<input type='hidden' name='price' value=" + price + ">");
            Response.Write("<input type='hidden' name='show_url' value=" + show_url + ">");
            Response.Write("<input type='hidden' name='seller_email' value=" + seller_email + ">");
            Response.Write("<input type='hidden' name='return_url' value=" + return_url + ">");
            Response.Write("<input type='hidden' name='notify_url' value=" + notify_url + ">");
            Response.Write("<input type='hidden' name='logistics_type' value=" + logistics_type + ">");
            Response.Write("<input type='hidden' name='logistics_fee' value=" + logistics_fee + ">");
            Response.Write("<input type='hidden' name='logistics_payment' value=" + logistics_payment + ">");
            Response.Write("<input type='hidden' name='payment_type' value=1>");
            Response.Write("<input type='hidden' name='quantity' value=" + quantity + ">");
            Response.Write("<input type='hidden' name='sign' value=" + aliay_url + ">");
            Response.Write("</form>");
            Response.Write("<script>");
            Response.Write("document.alipaysubmit.submit()");
            Response.Write("</script>");

            //以下是GET方式传递参数
            //Response.Redirect(aliay_url);
            #endregion
        }
    }
}

